import 'package:boss/models/package_group.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusPackage/provider/package_detail_provider.dart';
import 'package:boss/ui/widget/image/base_image.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class MustCommodityItem extends StatefulWidget {
  final CommodityFormList data;
  const MustCommodityItem({Key key,@required this.data}) : super(key: key);

  @override
  _MustCommodityItemState createState() => _MustCommodityItemState();
}

class _MustCommodityItemState extends State<MustCommodityItem> {
  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: Container(
        height: 80.w,
        child: Row(
          children: <Widget>[
            Expanded(
              child: Text(widget.data.commodityNameWithSku),
              flex: 3,
            ),
            Expanded(
              child: Text('¥' + AmountUtil.price2String(widget.data.price)),
              flex: 2,
            ),
            Expanded(
              child: TextFormField(
                textAlign: TextAlign.center,
                initialValue: widget.data.quantity.toString(),
                keyboardType: TextInputType.number,
                inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.integerReg)],
                onChanged: (value) {
                  widget.data.quantity = int.parse(value);
                },
              ),
              flex: 1,
            ),
            Container(
              margin: EdgeInsets.only(
                left: 15.w,
              ),
              child: GestureDetector(
                onTap: () {
                  var provider =Provider.of<PackageDetailProvider>(context, listen: false,);
                  provider.removeMustCommodity(widget.data);
                },
                child: BaseImage(
                  'assets/image/delete_icon.png',
                  width: 30.w,
                  height: 30.w,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
